package service

import (
	"community-service/internal/app/config"
	"community-service/internal/app/entity"
	"community-service/pkg/error"
	"community-service/pkg/utils"
	"github.com/gin-gonic/gin"
)

func Verify(c *gin.Context, post string) {
	var eu entity.User
	result := config.MYSQLDB.Table("users").Where("post = ?", post).First(&eu)
	if result.Error != nil {
		error.Response(c, error.BadRequest, gin.H{}, "邮箱不存在.")
		return
	}

	if utils.GenerateCode(eu.Post) {
		error.Response(c, error.OK, gin.H{}, "验证码发送成功.")
	} else {
		error.Response(c, error.BadRequest, gin.H{}, "验证码发送失败.")
	}
}
